from fastapi import FastAPI
import uvicorn
import asyncio
from app.nacos_client import register_service, send_heartbeat, watch_config
from app.routes import router
import app.settings as settings

# 创建 FastAPI 应用
app = FastAPI()

# 注册路由
app.include_router(router)


@app.on_event("startup")
async def startup_event():
    register_service()

    watch_config()

    # 启动心跳任务
    asyncio.create_task(send_heartbeat())

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=settings.SERVICE_PORT)
